package com.augurit.common.util;

import java.lang.reflect.Field;

/**
 * 反射工具类，继承springside3中ReflectionUtils
 */
public class ReflectionUtils extends org.springside.modules.utils.ReflectionUtils{

	/**
	 * 获取指定对象某一个属性的数据类型
	 * @param object
	 * @param fieldName
	 * @return
	 */
	public static Class getFieldType(final Object object, String fieldName){
		Field field = ReflectionUtils.getAccessibleField(object, fieldName) ;
		if(field == null){
			throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + object + "]");
		}
		
		return field.getType();
	}
	
	/**
	 * 获取一个类所有field数组
	 * @param c
	 * @return
	 */
	public static String[] getFieldArray(Class c){
		String[] result = null;
		Field[] fields = c.getDeclaredFields();
		
		if(fields != null && fields.length > 0){
			result = new String[fields.length];
			for(int i = 0; i < fields.length; i++){
				result[i] = fields[i].getName();
			}
		}
		return result;
	}
}
